package lesson13;

import lesson05.Test;

import java.io.*;
import java.util.Properties;

public class Test02 {
    public Properties readProperties(){
        Properties prop = new Properties();
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("1.properties");
            prop.load(fis);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return prop;

    }
    public void writeProperties(Properties properties){
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("1.properties");
            properties.store(fos,"这是注释");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args) {
        Test02 test02 = new Test02();
        Properties prop = test02.readProperties();
        System.out.println(prop.getProperty("name"));
        System.out.println(prop.getProperty("age"));

//        Properties prop = new Properties();
//        prop.setProperty("name","张三");
//        prop.setProperty("age","20");
//        test02.writeProperties(prop);

    }
}
